Skip to content

[SM6.10] LinAlg Validation: MatVecMul MatVecMulAdd - #8718

Merged
Ashley Coleman (V-FEXrt) merged 3 commits into
microsoft:mainfrom
V-FEXrt:linalg-matvecmul
Aug 6, 2026
Merged

Ashley Coleman (V-FEXrt) merged 3 commits into
microsoft:mainfrom
V-FEXrt:linalg-matvecmul

Conversation

@V-FEXrt

Copy link
Copy Markdown
Collaborator

Fixes #8503
Fixes #8504

Adds validation rules for MatVecMul and MatVecMulAdd DXIL operations

Copilot AI balanced review requested due to automatic review settings July 30, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds SM 6.10 validation for DXIL matrix-vector multiply operations.

Changes:

  • Validates matrix scope/use, dimensions, component interpretation, signed floating-point outputs, and bias compatibility.
  • Adds focused validation tests and updates shader-stage fixtures.
  • Registers and documents new diagnostics.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utils/hct/hctdb.py Registers validation rules.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-vs.ll Updates vertex-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-raytracing.ll Updates ray-tracing fixtures.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-ps.ll Updates pixel-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-node.ll Updates node-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-ms.ll Updates mesh-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-matvecmuladd.ll Tests invalid multiply-add operations.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-matvecmul.ll Tests invalid multiply operations.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-hs.ll Updates hull-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-gs.ll Updates geometry-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-ds.ll Updates domain-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-cs.ll Updates compute-stage fixture.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-as.ll Updates amplification-stage fixture.
tools/clang/test/CodeGenDXIL/hlsl/linalg/builtins/matrixvectormultiplyadd/nominal.hlsl Makes multiply-add codegen cases valid.
tools/clang/test/CodeGenDXIL/hlsl/linalg/builtins/matrixvectormultiply/nominal.hlsl Makes multiply codegen cases valid.
lib/DxilValidation/DxilValidationUtils.h Declares type formatting utility.
lib/DxilValidation/DxilValidationUtils.cpp Implements type formatting utility.
lib/DxilValidation/DxilValidation.cpp Implements operation validation.
docs/DXIL.rst Documents diagnostics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/DxilValidation/DxilValidation.cpp Resolved
Comment thread lib/DxilValidation/DxilValidation.cpp Resolved
Copilot AI review requested due to automatic review settings July 31, 2026 22:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated no new comments.

Suppressed comments (1)

lib/DxilValidation/DxilValidation.cpp:1147

  • For packed interpretations this value is the required physical vector length, not the matrix K dimension. For example, the new C21M4N8 test reports K dimension '2' even though its metadata declares K=8. This makes the diagnostic factually incorrect; either report both K and the packed vector length or rename the message to describe the required vector size.
        CI, ValidationRule::InstrLinAlgMatrixDimVectorMismatch,
        {"Input", std::to_string(InputVecTy->getNumElements()), "K",
         std::to_string(K)});

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated no new comments.

Suppressed comments (2)

lib/DxilValidation/DxilValidation.cpp:1141

  • The K-dimension check still runs when the interpretation is nonconstant or rejected. In those cases Interp is Invalid/unsupported and ComponentTypeElementsPerScalar falls through to 4, so the validator can emit an arbitrary, misleading vector-size error in addition to the real interpretation error. Only compute/check K after the interpretation has been validated, or make the helper represent unsupported types explicitly.
  unsigned ElementsPerScalar = ComponentTypeElementsPerScalar(Interp);
  unsigned K = (MatLATT.N + ElementsPerScalar - 1) / ElementsPerScalar;

utils/hct/hctdb.py:8645

  • This shared diagnostic is now also emitted for an invalid input-vector interpretation, where saying the type is disallowed “in LinAlg Matrix” is inaccurate and can send users looking at the matrix metadata instead of the interpretation operand. Please make the wording apply to both contexts (for example, “not allowed in this LinAlg operation”) and update the generated documentation/tests accordingly.
            "Component Type '%0' not allowed in LinAlg Matrix.",

@inbelic Finn Plummer (inbelic) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once comment is resolved

Comment on lines +1036 to +1037
default:
return 4;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth listing out the elements here or a comment as it isn't immediately obvious why this would the case.

nit: Also I would expect LastEntry/Invalid should maybe be 0? Although it is presumably unreachable in any case

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern of only listing out the native types was copied over from what we do in the linalg.h header (which this comment reminds me, I need to do BFloat16 = 2 here)

Happy to explictly list them and add a comment like 8bit => 4 elements

I think I'd rather asster on LastEntry/Invalid. IIRC ComponentTypeElementsPerScalar can be used as a divisor so 0 would be a really bad potential value

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! 1141

unsigned K = (MatLATT.N + ElementsPerScalar - 1) / ElementsPerScalar;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listing them and asserting otherwise sounds good to me

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I can't assert here because it'll crash the tests where we intentionally use invalid types to verify a validation error is raised. I think this we have the validation error it should be okay to add a comment along the lines of all other values are invalid and their usage is detected in other parts of the validator

Comment thread lib/DxilValidation/DxilValidation.cpp Resolved
Comment thread lib/DxilValidation/DxilValidation.cpp Resolved
// CHECK-LABEL: define void @main()

__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(4, 5, 4, 1, 2)]] mat;
__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(4, 4, 4, 0, 0)]] mat;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these numbers changing to workaround something that now would trigger a validation error?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

%5 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 11, i32 0 }) ; AnnotateHandle(res,props) resource: ByteAddressBuffer
%6 = call %dx.types.LinAlgMatrixC9M4N8U0S2 @dx.op.linAlgMatrixLoadFromDescriptor.mC9M4N8U0S2(i32 -2147483634, %dx.types.Handle %5, i32 0, i32 0, i32 0, i32 0) ; LinAlgMatrixLoadFromDescriptor(handle,offset,stride,layout,align)

; CHECK-NEXT: Function: main: error: Matrix Scope 'ThreadGroup' does not match expected scope Thread.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do you want to put single quotes around Thread in this diagnostic?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule I've been following is that 'foo' means foo was a variable provided by the user while just foo means foo is a fixed requirement of the operation. I was trying to match what I say for other operations but I don't think we have a clear style guide here

%8 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 11, i32 0 }) ; AnnotateHandle(res,props) resource: ByteAddressBuffer
%9 = call %dx.types.LinAlgMatrixC9M4N8U1S0 @dx.op.linAlgMatrixLoadFromDescriptor.mC9M4N8U1S0(i32 -2147483634, %dx.types.Handle %8, i32 0, i32 0, i32 0, i32 0) ; LinAlgMatrixLoadFromDescriptor(handle,offset,stride,layout,align)

; CHECK-NEXT: Function: main: error: Matrix Use 'B' does not match expected use A.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Same single quote comment here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated no new comments.

Suppressed comments (2)

tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-cs.ll:36

  • This newly added comment describes a 4x4 accumulator, but the declared %dx.types.LinAlgMatrixC4M4N5U2S2 and its target-type metadata both use M=4, N=5. Please keep the test documentation consistent with the actual matrix dimensions.
  ; Matrix<I32, 4, 4, Accumulator, ThreadGroup>

lib/DxilValidation/DxilValidation.cpp:1111

  • This adds user-visible SM 6.10 validation behavior, but docs/ReleaseNotes.md has no corresponding entry. Please add this MatVecMul/MatVecMulAdd validation work to the existing Experimental Shader Model 6.10 section, or point to the related PR that will provide the shared release-note coverage.
static void ValidateLinAlgMatVecMul(CallInst *CI, ValidationContext &ValCtx,
                                    const char *OpName = "LinAlgMatVecMul") {
  ValidateLinAlgOpParameters(CI, ValCtx);

@bob80905 Joshua Batista (bob80905) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@V-FEXrt
Ashley Coleman (V-FEXrt) merged commit be54291 into microsoft:main Aug 6, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap Aug 6, 2026
@V-FEXrt
Ashley Coleman (V-FEXrt) deleted the linalg-matvecmul branch August 6, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

LinAlg Validation: MatVecMulAdd LinAlg Validation: MatVecMul

4 participants